#include <iostream>
#include <string>
#include "test.pb.h" 

using namespace std;
using namespace fixbud; 

int main()
{
    // LoginResponse rsq;
    // ResultCode *rc = rsq.mutable_result();
    // rc->set_errcode(1);
    // rc->set_errmsg("登录失败");
    UserServicerrpc rpc();  

    GetFriendListsResponse rsp;
    ResultCode* rc = rsp.mutable_result();
    rc->set_errcode(0);
    rc->set_errmsg("");

    User* user1 = rsp.add_friend_list(); // 自动生成一个对象交给我们 
    user1->set_name("zhang san");
    user1->set_age(18); 
    user1->set_sex(User::MAN);

    User* user2 = rsp.add_friend_list(); // 自动生成一个对象交给我们 
    user2->set_name("li si");
    user2->set_age(25); 
    user2->set_sex(User::WOMAN);

    cout << rsp.friend_list_size() << endl;

    User tmp = rsp.friend_list(0); 
    string res;
    if (tmp.SerializeToString(&res))
    {
        cout << res << endl;
    }

    return 0;
}


int main1()
{
    // 创建对象请求 
    LoginRequest req;
    req.set_name("zhang san");
    req.set_pwd("123456");

    // 将对象序列化成字符串 
    string send_str;
    if (req.SerializeToString(&send_str))
    {
        cout << send_str << endl;
    }

    // 反序列化 
    LoginRequest reqB;
    if (reqB.ParseFromString(send_str))
    {
        cout << reqB.name() << " " << reqB.pwd() << endl;
    }

    return 0;
}